package com.wgy.day16.Math;

/**
 * Created by pc on 2020/11/11 23:50
 * Description: LearningJava
 */
/*java.util.Math 类是数学相关的工具类.里面提供大量的静态方法,完成与数学相关的操作
 * public static double abs(double num):获取绝对值
 * public static double ceil(double num):向上取整
 * public static double floor(double num):向下取整
 * public static double round(double num):四舍五入取整  整数是没有小数点的
 *  Math.PI 代表近似的圆周率常量。
 * */
public class Demo01Math {
    public static void main(String[] args) {
        //获取绝对值
        System.out.println(Math.abs(-3.67));//3.67
        System.out.println(Math.abs(0));    //0
        System.out.println(Math.abs(0.0));  //0.0

        //向上取整
        System.out.println(Math.ceil(0));  //0.0
        System.out.println(Math.ceil(0.9));//1.0
        System.out.println(Math.ceil(-0.9));//-0.0

        //向下取整
        System.out.println(Math.floor(0));  //0.0
        System.out.println(Math.floor(0.9));//0.0
        System.out.println(Math.floor(-0.9));//-1.0

        //四舍五入取整
        System.out.println(Math.round(0));  //0
        System.out.println(Math.round(0.9));//1
        System.out.println(Math.round(-0.9));//-1
        System.out.println(Math.round(-0.4));//0
    }
}
